using System;
using System.Collections;
using System.Collections.Generic;
using Game.UI;
using UnityEngine;
using UnityEngine.UI;

public class TipsWindow : UIWindow {
    public Vector2 DefaultOffset;
    
    private RectTransform mTransform;
    private Text mTxtDesc;
    private void Awake() {
        mTxtDesc = transform.Find("DescArea/TxtDesc").GetComponent<Text>();
        mTransform = transform.GetComponent<RectTransform>();
    }

    protected override void onOpen(object[] args) {
        Vector2 mousePos = GameInput.Ins.NormalInput.MouseMove.ReadValue<Vector2>();
        transform.position = mousePos + getOffset(mousePos);
        string txt = (string)args[0];
        mTxtDesc.text = txt;
    }

    private Vector2 getOffset(in Vector2 mousePos) {
        Vector2 offset = Vector2.zero;
        if (mousePos.x > Screen.width / 2) {
            offset.x = -DefaultOffset.x;
        } else {
            offset.x = DefaultOffset.x;
        }

        if (mousePos.y > Screen.height / 2) {
            offset.y = -DefaultOffset.y;
        } else {
            offset.y = DefaultOffset.y;
        }

        return offset;
    }
    
    protected override void onClose() {
        mTxtDesc.text = "";
    }
}
